package LeetCode.month04.day110;

import java.util.Arrays;

/**
 * @author 16778
 * @date 2025/11/20 15:57
 * @description
 */
public class No2589 {
    static void main() {
        findMinimumTime(new int[][]{{2,3,1},{4,5,1},{1,5,2}});
    }
    public static int findMinimumTime(int[][] tasks) {
        int n = tasks.length;
        Arrays.sort(tasks,(a,b)->a[1]-b[1]);
        int mx = tasks[n-1][1];
        int count = 0;
        boolean[] run = new boolean[mx+1];
        for (int i = 0; i < n; i++) {
            int start = tasks[i][0];
            int end = tasks[i][1];
            int dur = tasks[i][2];
            for (int j = start; j <=end ; j++) {
                if (run[j]) {
                    dur--;
                }
            }
            for (int j = end; dur>0 ; j--) {
                if(!run[j]){
                    run[j] = true;
                    dur--;
                    count++;
                }
            }
        }
        return count;
    }
}
